﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Dln.Common.Helper;
using System.Text;

public partial class MyTestDetial : System.Web.UI.Page
{
    protected DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        var RowNo = HttpContext.Current.Request.QueryString["RowNo"];
        var HospID = HttpContext.Current.Request.QueryString["HospID"];
        HttpCookie userCookie = HttpContext.Current.Request.Cookies["loginCookie"];
        string sql =@"SELECT  ROW_NUMBER() OVER ( ORDER BY main.rowno DESC ) sRowNo ,
                                        AUTOID rwxh ,
                                        ( ( CASE WHEN main.gztnr IS NULL THEN ''
                                                 ELSE main.gztnr
                                            END ) + ( CASE WHEN main.cdnr IS NULL THEN ''
                                                           ELSE main.cdnr
                                                      END ) + ( CASE WHEN main.gnnr IS NULL THEN ''
                                                                     ELSE main.gnnr
                                                                END ) + main.InForMation ) tInForMation ,
                                        main.Note tNote ,
                                        a.EmpName kfempname ,
                                        {0} kfyjwcsj ,
                                        {1} kfwcsj 
                                FROM    {2} k
                                        LEFT JOIN hosp ON k.HospID = hosp.hospid
                                        LEFT JOIN Emp a ON k.empid = a.EmpID
                                        LEFT JOIN main ON k.HospID = main.hospid
                                                          AND k.rowno = main.rowno ";
        if (userCookie != null)
        {
            if (userCookie["IdNum"] != null)
            {
                DataTable dts = SqlHelper.GetDataTable(string.Format("SELECT ORGID FROM dbo.BHD03030 with(nolock) WHERE EMPID = '{0}'", userCookie["IdNum"].ToString()));
                if (dts != null && dts.Rows.Count > 0)
                {
                    //开发
                    if (dts.Rows[0]["ORGID"].ToString().Substring(0, 4) == "0303")
                    {
                        sql = string.Format(sql, "k.kfyjwcsj", "k.kfwcsj", "kfff");
                    }
                    else if (dts.Rows[0]["ORGID"].ToString().Substring(0, 4) == "0304")   //测试
                    {
                        sql = string.Format(sql, "k.csyjwcsj", "k.cswcsj", "csff");
                    }
                    StringBuilder forsql = new StringBuilder(sql);
                    forsql.AppendFormat("WHERE   1 = 1 AND k.HospID = '{0}' AND k.RowNo = {1}  AND a.EMPID='{2}'", HospID, RowNo, userCookie["IdNum"].ToString());
                    dt = SqlHelper.GetDataTable(forsql.ToString());
                }
            }
        }
    }
}